<?php
$menumark = 'sale_sta';
switch ($act) {
    //#####################@ 修改分类 @#####################//
    case 'order_detail':
        include(pe_tpl('orderdetail.html'));
        break;


    case 'find':

        break;


    case 'ordersta_detail_today':
        $start_time = date('Y-m-d H:i:s', strtotime(date('Y-m-d', time()) . ' 00:00:00'));  //当天开始时间
        $end_time = date('Y-m-d H:i:s', strtotime(date("Y-m-d") . ' 24:00:00')); //当天结束时间
        $sql = "select * from wxgg_order where order_subdate >   '$start_time'  and order_subdate <  '$end_time' and (order_ostate= 1 or order_ostate= 2) ";
        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }

        include(pe_tpl('order_list.html'));
        break;

    case 'ordersta_detail_week':
        //当前日期
        $sdefaultDate = date("Y-m-d");
        //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
        $first = 1;
        //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
        $w = date('w', strtotime($sdefaultDate));
        //获取本周开始日期，如果$w是0，则表示周日，减去 6 天
        $week_start = date('Y-m-d H:i:s', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
        //本周结束日期
        $week_end = date('Y-m-d H:i:s', strtotime("$week_start +6 days"));

        $sql = "select * from wxgg_order where order_subdate >   '$week_start'  and order_subdate <  '$week_end' and (order_ostate= 1 or order_ostate= 2)";
        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }

        include(pe_tpl('order_list.html'));
        break;

    case 'ordersta_detail_month':
        //获取本月开始的时间戳
        $beginThismonth = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), 1, date('Y')));
        //获取本月结束的时间戳
        $endThismonth = date('Y-m-d H:i:s', mktime(23, 59, 59, date('m'), date('t'), date('Y')));

        $sql = "select * from wxgg_order where order_subdate >   '$beginThismonth'  and order_subdate <  '$endThismonth' and (order_ostate= 1 or order_ostate= 2)";


        $order = $db->sql_selectall($sql);
        foreach ($order as $k => $v) {
            $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
            $order[$k]['order_housename'] = $house['house_name'];
        }

        include(pe_tpl('order_list.html'));
        break;


    case 'add':

        if (isGet()) {


            include(pe_tpl('order_add.html'));
        } else if (isPost()) {


            $result = $db->pe_insert("order", $_p_info);
            if ($result) {
                pe_success('添加成功', 'admin.php?mod=order&act=add');
            } else {
                pe_error('添加失败');
            }

        }

        break;

    case 'find_sale':
        if(empty($_g_in_date)){
            pe_error('统计开始时间不能为空');
        }
        $start_time = strtotime($_g_in_date);
        $end_time = strtotime($_g_out_date);
        $m_sql = 'select sum(order_endprice) total_price from wxgg_order where order_startdate > '.$start_time.' and order_startdate < '.$end_time ;
        if(!empty($end_time)){

            //是vip数据
            $vip_sql = $m_sql . ' and order_isvip = 1 or order_isvip = 2';
            $vip_order = $db->sql_select($vip_sql);
            //不是vip数据
            $not_vip_sql = $m_sql . ' and order_isvip = 0';
            $not_vip_order = $db->sql_select($not_vip_sql);
            //储蓄卡支付方式数据
            $db_card_sql = $m_sql . ' and order_payway = 2';
            $db_card_order = $db->sql_select($db_card_sql);
            //微信支付方式数据
            $wx_sql = $m_sql . ' and order_payway = 3';
            $wx_order = $db->sql_select($wx_sql);
            //线下支付数据
            $offline_sql = $m_sql . ' and order_payway = 1' ;
            $offline_order = $db->sql_select($offline_sql);

            //线上支付数据
            $online_sql = $m_sql . ' and order_payway = 2 or order_payway = 3';
            $online_order = $db->sql_selectall($online_sql);

        }
        include(pe_tpl('salesta_list.html'));
        break;


    //#####################@ 分类列表 @#####################//
    default :
        //本日
        $start_time = date('Y-m-d H:i:s', strtotime(date('Y-m-d', time()) . ' 00:00:00'));  //当天开始时间
        $end_time = date('Y-m-d H:i:s', strtotime(date("Y-m-d") . ' 24:00:00')); //当天结束时间
        $sql = "select * from wxgg_order where order_subdate >   '$start_time'  and order_subdate <  '$end_time' and (order_ostate= 1 or order_ostate= 2)";
        $today_order = $db->sql_selectall($sql);
        $today_order_allmoney = 0;
        if (count($today_order)>0)
            foreach ($today_order as $k => $v) {{
                $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                $today_order[$k]['order_housename'] = $house['house_name'];
                $today_order_allmoney = $today_order_allmoney + $v['order_endprice'];
            }
            }
        $today_order_amount = count($today_order);//订单总数
        //本日结束


        //本周
        $sdefaultDate = date("Y-m-d"); //当前日期
        //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
        $first = 1;
        //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
        $w = date('w', strtotime($sdefaultDate));
        //获取本周开始日期，如果$w是0，则表示周日，减去 6 天
        $week_start = date('Y-m-d H:i:s', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
        //本周结束日期
        $week_end = date('Y-m-d H:i:s', strtotime("$week_start +6 days"));

        $sql = "select * from wxgg_order where order_subdate >   '$week_start'  and order_subdate <  '$week_end' and (order_ostate= 1 or order_ostate= 2)";
        $week_order = $db->sql_selectall($sql);
        if (count($week_order)>0) {
            foreach ($week_order as $k => $v) {
                $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                $week_order[$k]['order_housename'] = $house['house_name'];
                $week_order_allmoney = $week_order_allmoney + $v['order_endprice'];
            }
        }
        $week_order_amount = count($week_order);//订单总数
        //本周结束

        //本月
        //获取本月开始的时间戳
        $beginThismonth = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), 1, date('Y')));
        //获取本月结束的时间戳
        $endThismonth = date('Y-m-d H:i:s', mktime(23, 59, 59, date('m'), date('t'), date('Y')));

        $sql = "select * from wxgg_order where order_subdate >   '$beginThismonth'  and order_subdate <  '$endThismonth' and (order_ostate= 1 or order_ostate= 2)";

        $month_order['order_allmoney'] = 0;
        $month_order = $db->sql_selectall($sql);
        if (count($month_order)>0) {
            foreach ($month_order as $k => $v) {
                $house = $db->pe_select('house', array('house_id' => $v['order_houseid']));
                $month_order[$k]['order_housename'] = $house['house_name'];
                $month_order_allmoney = $month_order_allmoney + $v['order_endprice'];
            }
        }
        $month_order_amount = count($month_order);//订单总数
        //本月结束



        include(pe_tpl('salesta_list.html'));

        break;
}



?>


